<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";
include "../resources/base64/functions.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_GET['date'])) {
    exit("需要传入有效的参数。");
}

$date = $_GET['date'];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath;
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

try {

    $content = $db->readFromFinished($date);

    // 加这个判断是为了兼容旧版本
    // 旧版本中的 finished 表中存放的数据都是 base64 编码过的
    // 新版本中的 finished 表中存放的数据都是 base64 解码过的原始字符串
    if (isBase64($content)) {
        echo $content;
    } else {
        echo utf8_to_b64($content);
    }

} catch (Exception $e) {
    echo $e->getMessage();
}
